#!/bin/bash
clear

TEXT='\033[30;107;2m'
INFO='\033[97;44m'
WARNING='\033[97;43m'
ERROR='\033[97;41m'
SUCCESS='\033[97;42m'
GREEN='\033[92m'
YELLOW='\033[93m'
RESET='\033[0m'

if [ "${EUID}" -ne 0 ]; then
    echo -e "${ERROR} RALAT ${RESET}${TEXT} You need to run this script as root! ${RESET}"; exit 1
fi

clear
echo
echo -e "${TEXT} ========================================================== ${RESET}"
echo -e "${TEXT} SENARAI AKAUN                                              ${RESET}"
echo -e "${TEXT} ---------------------------------------------------------- ${RESET}"
echo
while read file; do
    senarai_klien="$(echo $file | cut -d ":" -f 1)"
    tarikh_luput="$(chage -l $senarai_klien | grep "Account expires" | awk -F": " '{print $2}')"
    user_uid="$(echo $file | grep -v nobody | cut -d ":" -f 3)"
    if [[ $user_uid -ge 1000 ]]; then
        printf "%-15s %2s\n" "$senarai_klien" "$tarikh_luput"
    fi
done < /etc/passwd
jumlah_klien="$(awk -F ":" '$3 >= 1000 && $1 != "nobody" {print $1}' /etc/passwd | wc -l)"

echo
echo -e "${SUCCESS} JUMLAH ${RESET}${TEXT} $jumlah_klien pengguna ${RESET}"
echo
echo -e "${TEXT} ---------------------------------------------------------- ${RESET}"
echo -e "${TEXT} Created by Doctype, Powered by Cybertize.                  ${RESET}"
echo -e "${TEXT} Copyright 2021, Allright Reserved.                         ${RESET}"
echo -e "${TEXT} ========================================================== ${RESET}"
echo